import struct
import sys
from pympler import asizeof

class Node1:
    def __init__(self, x, y):
        self.x = x
        self.y = y
        self.parent = (1,2)

class Node2:
    def __init__(self, x, y):
        self.x = x
        self.y = y

if __name__ == '__main__':

    node1 = Node1(1, 2)
    node2 = Node2(1, 2)
    node1.parent = node2

    print("Node1 size:", sys.getsizeof(node1))
    print("Node2 size:", sys.getsizeof(node2))
    print(asizeof.asizeof(node1))  # 输出 node1 的总内存占用，包括 parent 引用的对象
    print(asizeof.asizeof(node2))  # 输出 node2 的总内存占用
    # 逐个检查属性的大小
    print("Node1 attributes size:")
    print("x size:", sys.getsizeof(node1.x))
    print("y size:", sys.getsizeof(node1.y))
    print("parent size:", sys.getsizeof(node1.parent))

    print("Node2 attributes size:")
    print("x size:", sys.getsizeof(node2.x))
    print("y size:", sys.getsizeof(node2.y))

    # 直接获取整数4字节的字节表示
    packed_x = struct.pack('i', node1.x)
    print("Packed size:", len(packed_x))  # 应该是4字节